//
//  TaskViewController.swift
//  willdo
//
//  Created by zz on 3/14/18.
//  Copyright © 2018 will do. All rights reserved.
//

import UIKit
import PagingMenuController

class TaskViewController: UIViewController, PagingMenuControllerCustomizable {

    private var pageingControllers:[UIViewController]{
        let myTask = MyTaskViewController()
        let myReview = MyTaskViewController()
        let archive = MyTaskViewController()
        
        return [myTask, myReview, archive]
    }
    
    
    var defaultPage: Int{
        return 0
    }
    
    var componentType: ComponentType{
        return .all(menuOptions: MenuOptions(), pagingControllers: pageingControllers)
    }
    
    struct MenuOptions:MenuViewCustomizable {
        var backgroundColor: UIColor{
            return UIColor.white
        }
        var selectedBackgroundColor : UIColor{
            return UIColor.white
        }
        var displayMode: MenuDisplayMode{
            return .segmentedControl
        }
        var focusMode: MenuFocusMode{
            return .underline(height: 3, color: UIColor(hexString:"416ba3") , horizontalPadding: 44, verticalPadding: 0)
        }
        var height: CGFloat{
            return 43
        }

        var itemsOptions: [MenuItemViewCustomizable]{
            return [myTaskMenu(), myReviewMenu(), archiveMenu()]
        }
        
        struct myTaskMenu: MenuItemViewCustomizable{
            var displayMode:MenuItemDisplayMode{
                let title = MenuItemText(text: "我的任务", color: UIColor(hexString: "#666666"), selectedColor: UIColor(hexString: "#5181b0"), font: UIFont.init(name: "PingFang SC", size: 17)!, selectedFont: UIFont.init(name: "PingFang SC", size: 17)!)
                return .text(title: title)
            }
        }
        struct myReviewMenu: MenuItemViewCustomizable {
            var displayMode:MenuItemDisplayMode{
                let title = MenuItemText(text: "待我审核", color: UIColor(hexString: "#666666"), selectedColor: UIColor(hexString: "#5181b0"), font: UIFont.init(name: "PingFang SC", size: 17)!, selectedFont: UIFont.init(name: "PingFang SC", size: 17)!)
                return .text(title: title)
            }
        }
        struct archiveMenu: MenuItemViewCustomizable  {
            var displayMode:MenuItemDisplayMode{
                let title = MenuItemText(text: "归档任务", color: UIColor(hexString: "#666666"), selectedColor: UIColor(hexString: "#5181b0"), font: UIFont.init(name: "PingFang SC", size: 17)!, selectedFont: UIFont.init(name: "PingFang SC", size: 17)!)
                return .text(title: title)
            }
        }
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "任务"

        self.edgesForExtendedLayout = UIRectEdge(rawValue: 0)
        let avaterImg = UIImage(named: "head portrait")?.withRenderingMode(.alwaysOriginal)
        let avaterBtn = UIBarButtonItem(image: avaterImg, style: .plain, target: self, action: nil)
        let searchImg = UIImage(named: "search_btn")?.withRenderingMode(.alwaysOriginal)
        let searchBtn = UIBarButtonItem(image: searchImg, style: .plain, target: self, action: nil)
        let addImg = UIImage(named:"add_btn")?.withRenderingMode(.alwaysOriginal)
        let addBtn = UIBarButtonItem(image: addImg, style: .plain, target: self, action: #selector(addTask))
        self.navigationItem.leftBarButtonItem = avaterBtn
        self.navigationItem.rightBarButtonItems = [addBtn, searchBtn]
        
        
        let page = PagingMenuController(options: self)
        
        addChildViewController(page)
        view.addSubview(page.view)
        
    }
    
    
    @objc func addTask(){
        let addVC = AddTaskViewController()
        addVC.hidesBottomBarWhenPushed = true
        navigationController?.pushViewController(addVC, animated: true)
    }
}
